home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / nihcl-30.lha / nihcl-3.0 / lib / _main.c_p < prev    next >
Text File  |  1990-05-23  |  2KB  |  87 lines

  1. /* _main.c -- "patch" version with NIH Class Library initialization
  2.  
  3.     THIS SOFTWARE FITS THE DESCRIPTION IN THE U.S. COPYRIGHT ACT OF A
  4.     "UNITED STATES GOVERNMENT WORK".  IT WAS WRITTEN AS A PART OF THE
  5.     AUTHOR'S OFFICIAL DUTIES AS A GOVERNMENT EMPLOYEE.  THIS MEANS IT
  6.     CANNOT BE COPYRIGHTED.  THIS SOFTWARE IS FREELY AVAILABLE TO THE
  7.     PUBLIC FOR USE WITHOUT A COPYRIGHT NOTICE, AND THERE ARE NO
  8.     RESTRICTIONS ON ITS USE, NOW OR SUBSEQUENTLY.
  9.  
  10. Author:
  11.     Ted Persky
  12.     Bg. 12A, Rm. 2031
  13.     Computer Systems Laboratory
  14.     Division of Computer Research and Technology
  15.     National Institutes of Health
  16.     Bethesda, Maryland 20892
  17.     Phone: (301) 496-2963
  18.     uucp: uunet!nih-csl!ted
  19.     December, 1988
  20.  
  21. Function:
  22.     _main is called at execution time before the programmer's
  23.     "main" program.  It runs through the __linkl linked list
  24.     of constructors and calls them all to initialize static and
  25.     external objects.  It finally calls the NIH Class Library
  26.     initialization routine.
  27.  
  28. Modification History:
  29.  
  30. $Log:    _main.c_p,v $
  31. Revision 3.0  90/05/23  11:01:46  kgorlen
  32. Release for 1st edition.
  33.  
  34. */
  35.  
  36. #include "Object.h"
  37.  
  38. static char RCSID[] = "$Header: /afs/alw.nih.gov/unix/sun4_40c/usr/local/src/nihcl-3.0/share/lib/RCS/_main.c_p,v 3.0 90/05/23 11:01:46 kgorlen Rel $";
  39.  
  40. typedef int (*PFI) ();
  41.  
  42. struct staticCtorDtorLink {
  43.     struct staticCtorDtorLink* next;    //next link in the chain
  44.     PFI ctor;        //ptr to ctor function
  45.     PFI dtor;        //ptr to dtor function
  46. };
  47.  
  48. #ifdef __cplusplus
  49.  
  50. extern "C" { extern void _main(); };
  51. struct staticCtorDtorLink* __head;
  52.  
  53. #else
  54.  
  55. struct staticCtorDtorLink* __HEAD;
  56.  
  57. #endif
  58.  
  59. extern void _main()
  60. {
  61.  
  62. #ifdef __cplusplus
  63.     struct staticCtorDtorLink* current = __head;
  64.     struct staticCtorDtorLink* previous = 0;
  65. #else
  66.     struct staticCtorDtorLink* current = __HEAD;
  67. #endif
  68.  
  69.     while (current != (staticCtorDtorLink*)0) {
  70.         if (current->ctor != (PFI) 0) (*(current->ctor))();
  71. #ifdef __cplusplus
  72.         struct staticCtorDtorLink* next = current->next;
  73.         current->next = previous;
  74.         previous = current;
  75.         current = next;
  76. #else
  77.         current = current->next
  78. #endif
  79.     }
  80.  
  81. #ifdef __cplusplus
  82.     __head = previous;
  83. #endif
  84.  
  85.     NIHCL::initialize();
  86. }
  87.